package com.hnkywl.sts.dao.flow;

import com.hnkywl.sts.entity.flow.FlowConfigure;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.tool.hbm2x.StringUtils;
import org.springframework.stereotype.Repository;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-6-16
 * Time: 下午5:10
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class LcpzDao extends SimpleHibernateTemplate<FlowConfigure, Long> {
    public Page<FlowConfigure>  findLcpzList(String name, int pageNo, int pageSize) {
        Page<FlowConfigure> page = new Page<FlowConfigure>();
        page.setAutoCount(true);
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setOrder("desc");
        page.setOrderBy("lastUpdated");
        if (StringUtils.isNotEmpty(name)) {
            return this.findByCriteria(page, new Criterion[]{Restrictions.like("flowName", name, MatchMode.START)});
        }  else
            return this.findAll(page);
    }

}
